<?php

\Phpcmf\Hooks::on('cms_init', function() {
    // 微信中访问网站时，未登录时直接授权微信登录
	if (IS_API || IS_API_HTTP
        || in_array(APP_DIR, ['weixin', 'api', 'member'])
        || in_array(\Phpcmf\Service::L('Router')->class, ['register', 'login', 'api'])) {
		return;
	} elseif (!IS_MEMBER && !\Phpcmf\Service::C()->uid) {
		$config = \Phpcmf\Service::M('Weixin', 'Weixin')->get_config('config'); // 配置
		if (isset($config['autologin']) && $config['autologin']
			&& strpos((string)$_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
			dr_redirect(SITE_URL.'index.php?s=weixin&c=go&url='.urlencode(FC_NOW_URL));
		}
	}
});